package com.breeze.components.limiter.implementation;

import com.breeze.components.limiter.anno.RateLimit;

/**
 * @author breeze
 */
public abstract class AbstractRateLimitChecker {

  /**
   * 检查是否超出限流
   *
   * @param rateLimit RateLimit
   */
  public abstract void check(RateLimit rateLimit, String combineKey);

  /**
   * 限流
   *
   * @param runnable 执行逻辑
   * @param combinedKey key
   * @param permits 许可数量
   * @param rateLimit 限制数量
   * @param rateTime 时间 单位:s
   */
  public abstract void tryAcquire(
      Runnable runnable, String combinedKey, int permits, int rateLimit, int rateTime);

  public void tryAcquire(Runnable runnable, String combinedKey, int permits, int rateLimit) {
    tryAcquire(runnable, combinedKey, permits, rateLimit, 1);
  }

  public void tryAcquire(Runnable runnable, String combinedKey, int rateLimit) {
    tryAcquire(runnable, combinedKey, 1, rateLimit, 1);
  }
}
